<template>
  <div class="collect-page">
    <van-nav-bar fixed :title="'我的喜欢(' + likeCount + ')'" />
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <ArticleItem v-for="(item) in list" :key="item.id" :item="item" />
    </van-list>

  </div>

</template>

<script>
import { getOptAPI } from '@/api/article'
import ArticleItem from '@/components/ArticleItem'

export default {
  name: 'collect-page',
  components: { ArticleItem },
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      pageTotal: 99,
      likeCount: 0
    }
  },
  methods: {
    async onLoad () {
      // 异步更新数据
      const res = await getOptAPI({ page: this.page, type: 1 })
      this.list.push(...res.data.rows)
      console.log('收藏数据  ----->  ', res.data)
      this.pageTotal = res.data.pageTotal
      this.likeCount = res.data.total
      this.loading = false
      this.page++

      if (this.page > this.pageTotal) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.collect-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
